package org.sakai.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.sakai.entity.ApiResponseEntity;
import org.sakai.entity.Consult;
import org.sakai.entity.Patient;
import org.sakai.entity.Result;
import org.sakai.entity.dto.ConsultRequestDto;
import org.sakai.entity.vo.ConsultVO;
import org.sakai.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    PatientService patientService;
    @GetMapping("/list/{userId}")
    public ResponseEntity<List<Patient>> getMyList(@PathVariable String userId) {
        Result<List<Patient>> patientListResult = patientService.getPatientList(userId);
        return ApiResponseEntity.getResponseEntity(patientListResult);
    }

    @PostMapping("/info")
    public ResponseEntity<Patient> getPatientById(@RequestBody Map<String, String> map) {
        String userId = String.valueOf(map.get("userId"));
        String patientId = String.valueOf(map.get("patientId"));
        Result<Patient> patientResult = patientService.getPatientInfo(userId, patientId);
        return ApiResponseEntity.getResponseEntity(patientResult);
    }

    @PostMapping("/add")
    public ResponseEntity<String> addPatient(@RequestBody Patient patient) {
        Result<String> result = patientService.addPatient(patient);
        return ApiResponseEntity.getResponseEntity(result);
    }

    @PutMapping("/update")
    public ResponseEntity<String> updatePatient(@RequestBody Patient patient) {
        Result<String> result = patientService.updatePatient(patient);
        return ApiResponseEntity.getResponseEntity(result);
    }

    @DeleteMapping("/del/{patientId}")
    public ResponseEntity<String> delPatient(@PathVariable String patientId) {
        Result<String> result = patientService.delPatient(patientId);
        return ApiResponseEntity.getResponseEntity(result);
    }

    @GetMapping("/consult/order/list")
    public ResponseEntity<List<Consult>> getConsultOrderListByPatientId(
            @RequestParam("userId")String uid,
            @RequestParam("current")Integer current,
            @RequestParam("pageSize")Integer pageSize) {
        Result<List<ConsultVO>> result = patientService.getConsultOrderListByPatientId(uid, current, pageSize);
        return ApiResponseEntity.getResponseEntity(result);
    }

    @GetMapping("/consult/order/detail/{id}")
    public ResponseEntity<ConsultVO> getConsultOrderDetailByOrderId(@PathVariable String id) {
        Result<ConsultVO> result = patientService.getConsultOrderDetailByOrderId(id);
        return ApiResponseEntity.getResponseEntity(result);
    }
}
